package com.douqu.game.core.entity.ext.data.boon;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bean.core.buffer.ByteBuffer;
import com.douqu.game.core.config.LotteryConfig;
import com.douqu.game.core.config.StableDataConfig;
import com.douqu.game.core.controller.PlayerController;
import com.douqu.game.core.e.E_LotteryType;
import com.douqu.game.core.e.E_StableDataType;
import com.douqu.game.core.entity.Player;
import com.douqu.game.core.entity.db.*;
import com.douqu.game.core.entity.ext.BagInfo;
import com.douqu.game.core.entity.ext.TaskInfo;
import com.douqu.game.core.entity.ext.data.BaseData;
import com.douqu.game.core.factory.*;
import com.douqu.game.core.protobuf.SGMainProto;
import com.douqu.game.core.protobuf.SGPlayerProto;
import com.douqu.game.core.util.CoreUtils;
import com.douqu.game.core.util.LogUtils;

import java.util.List;

/**
 * @Author: Bean
 * @Description:
 * @Date: 2017-10-30 17:05
 */
public class LotteryData extends BaseData {

	// /**
	// * 抽奖次数
	// * key: 类型
	// * value: 抽奖数据
	// */
	// public Map<Integer,SingleBoonData> lotteryMap;

	private LotteryDB goldSingleDB;

	private LotteryDB goldMuchDB;

	private LotteryDB diamondSingleDB;

	private LotteryDB diamondMuchDB;

	/**
	 * 定时器是否推送过了
	 */
	public boolean hasPushRedPointRemind = false;

	private Player player;

	public LotteryData(Player player) {
		this.player = player;
		// lotteryMap = new ConcurrentHashMap<>();
		hasPushRedPointRemind = false;

		goldSingleDB = new LotteryGoldSingleDB(DataFactory.LOTTERY_KEY);
		goldMuchDB = new LotteryGoldMuchDB(DataFactory.LOTTERY_KEY);
		diamondSingleDB = new LotteryDiamondSingleDB(DataFactory.LOTTERY_KEY);
		diamondMuchDB = new LotteryDiamondMuchDB(DataFactory.LOTTERY_KEY);
	}

	@Override
	public void init() {
		List<LotteryConfig> list = DataFactory.getInstance().getDataList(DataFactory.LOTTERY_KEY);
		for (LotteryConfig object : list) {
			if (object.type == 1 && object.level == 1)
				goldSingleDB = new LotteryGoldSingleDB(DataFactory.LOTTERY_KEY, object.id);
			else if (object.type == 1 && object.level == 2)
				goldMuchDB = new LotteryGoldMuchDB(DataFactory.LOTTERY_KEY, object.id);
			else if (object.type == 2 && object.level == 1)
				diamondSingleDB = new LotteryDiamondSingleDB(DataFactory.LOTTERY_KEY, object.id);
			else if (object.type == 2 && object.level == 2)
				diamondMuchDB = new LotteryDiamondMuchDB(DataFactory.LOTTERY_KEY, object.id);

		}
	}

	@Override
	public void checkInit() {

		if (goldSingleDB.id == 0) {
			init();
		}
	}

	@Override
	public void reset() {
		goldSingleDB.reset();
		goldMuchDB.reset();
		diamondSingleDB.reset();
		diamondMuchDB.reset();
	}

	@Override
	public void checkReset() {

		if (!goldSingleDB.isTodayByOffset() || !diamondSingleDB.isTodayByOffset()) {
			reset();
		}
	}

	@Override
	public void writeTo(ByteBuffer buffer) {
		goldSingleDB.writeTo(buffer);
		goldMuchDB.writeTo(buffer);
		diamondSingleDB.writeTo(buffer);
		diamondMuchDB.writeTo(buffer);
	}

	@Override
	public void loadFrom(ByteBuffer buffer) {
		goldSingleDB.loadFrom(buffer);
		goldMuchDB.loadFrom(buffer);
		diamondSingleDB.loadFrom(buffer);
		diamondMuchDB.loadFrom(buffer);
	}

	/**
	 * 是否有红点
	 * 
	 * @return
	 */
	public boolean hasRedPointRemind(boolean isScheduleTask, long currentTime) {
		if (hasPushRedPointRemind && isScheduleTask) {
			return false;
		}
		boolean has = false;

		if (goldSingleDB.getFreeCount() > 0)
			has = goldSingleDB.getCDTime() <= 0;

		if (!has && diamondSingleDB.getFreeCount() > 0)
			has = diamondSingleDB.getCDTime() <= 0;

		if (has && isScheduleTask) {
			hasPushRedPointRemind = true;
		}
		return has;
	}

	/**
	 * 是否有钻石免费次数(气泡信息)
	 * @return
	 */
	public boolean hasDiamondFree(){
		if(!CoreUtils.isFunctionUnLock(FunctionFactory.UNLOCK_LOTTERY, player)){
			return false;
		}
		return diamondSingleDB.getFreeCount() > 0 && diamondSingleDB.getCDTime() <= 0;
	}

	/**
	 * 是否有酒杯十连抽
	 * @return
	 */
	public boolean hasItemTenFree(){
		if(!CoreUtils.isFunctionUnLock(FunctionFactory.UNLOCK_LOTTERY, player)){
			return false;
		}

        LotteryConfig lotteryConfig = DataFactory.getInstance().getLotteryConfigByID(5);
        if (lotteryConfig == null) {
            return false;
        }
		return player.getExtInfo(BagInfo.class).getPropCount(lotteryConfig.priorityUse.id) >= lotteryConfig.priorityUse.value;
	}

	// /**
	// * 抽奖
	// * @param playerController
	// * @param type
	// * @param buyType
	// */
	// public void getCommonLottery(PlayerController playerController, int type, int
	// buyType)
	// {
	// if(type != E_LotteryType.ONCE.getCode() && type !=
	// E_LotteryType.REPEATEDLY.getCode())
	// {
	// playerController.sendWarn(WordFactory.ILLEGAL_ERROR);
	// return;
	// }
	// if(buyType != E_LotteryType.ONCE.getCode() && buyType !=
	// E_LotteryType.REPEATEDLY.getCode())
	// {
	// playerController.sendWarn(WordFactory.ILLEGAL_ERROR);
	// return;
	// }
	//
	// //获取抽奖数据
	// SingleBoonData lotteryData = lotteryMap.get(type);
	// if(lotteryData == null) {
	// playerController.sendWarn(WordFactory.CURRENT_LOTTERY);
	// return;
	// }
	// BagInfo bagInfo = playerController.getPlayer().getExtInfo(BagInfo.class);
	// SGPlayerProto.S2C_LotteryClick.Builder b =
	// SGPlayerProto.S2C_LotteryClick.newBuilder();
	//
	// LotteryConfig lotteryConfig =
	// DataFactory.getInstance().getGameObject(DataFactory.LOTTERY_KEY,
	// lotteryData.id);
	// long currentTime = DataFactory.currentTime;
	// if (type == E_LotteryType.ONCE.getCode() ){
	// if(buyType == E_LotteryType.ONCE.getCode()){
	// if((lotteryData.currentNum + 1) % lotteryConfig.nextLevelCount == 0){
	// lotteryConfig = DataFactory.getInstance().getNextLevelLottery(type,
	// lotteryConfig.level);
	// }
	//
	// }else{
	// lotteryConfig = DataFactory.getInstance().getNextLevelLottery(type,
	// lotteryConfig.level);
	//// deduction = lotteryConfig.needAsset.value;
	// }
	// } else {
	// if(buyType == E_LotteryType.ONCE.getCode()){
	// if((lotteryData.currentNum + 1) % lotteryConfig.nextLevelCount == 0){
	// lotteryConfig = DataFactory.getInstance().getNextLevelLottery(type,
	// lotteryConfig.level);
	// }
	//// deduction = lotteryConfig.needAsset.value ;
	// }else{
	//
	//
	// LotteryConfig tenObject = DataFactory.getInstance().getNextLevelLottery(type,
	// lotteryConfig.level);
	// if(lotteryData.fistSeniorLotteryTime == 0){
	// lotteryConfig = DataFactory.getInstance().getNextLevelLottery(type,
	// tenObject.level);
	// }else{
	// int c = lotteryData.currentNum;
	// int d = (c/40 +1) * 40;
	// if (c <= d && d <= c+10 && (c % 40 != 0)){
	// lotteryConfig = DataFactory.getInstance().getNextLevelLottery(type,
	// tenObject.level);
	//// deduction = lotteryConfig.needAsset.value ;
	// } else {
	// lotteryConfig = tenObject;
	//// deduction = lotteryConfig.needAsset.value ;
	// }
	// }
	//
	// }
	// }
	// int deduction = 0;
	// GoodsData bisong = lotteryConfig.reward;
	// if(type == E_LotteryType.ONCE.getCode() ){
	// if(buyType == E_LotteryType.ONCE.getCode()){
	// deduction = 10000 ;
	// }else if (buyType == E_LotteryType.REPEATEDLY.getCode()){
	// deduction = 10000 * 10;
	// }
	// }else if (type == E_LotteryType.REPEATEDLY.getCode()){
	// if(buyType == E_LotteryType.ONCE.getCode()){
	// deduction = 300 ;
	// }else if (buyType == E_LotteryType.REPEATEDLY.getCode()){
	// deduction = 2800;
	// bisong = lotteryConfig.reward.copyNew();
	// bisong.value = 500;
	// }
	// }
	//
	//
	// boolean cdTimeFlag = buyType == E_LotteryType.ONCE.getCode() && currentTime -
	// lotteryData.lastUpdateTime >= lotteryConfig.cdTime;
	// //没有免费次数检测cd时间是否未到
	// if(lotteryData.freeCount <= 0 || !cdTimeFlag) {
	//
	//
	// //检测资源是否足够
	// if(bagInfo.getAsset(lotteryConfig.needAsset.id) < deduction) {
	// //资源不够
	// LogUtils.debug("钻石不够,需要 -> " + lotteryConfig.needAsset.value + " " +
	// lotteryConfig.getName());
	// playerController.sendWarn(WordFactory.ASSET_NOT_ENOUGH,
	// lotteryConfig.needAsset.id);
	// return;
	// }
	//
	// }
	//
	// if(lotteryData.freeCount > 0) {
	// if(!cdTimeFlag){
	// bagInfo.addAsset(lotteryConfig.needAsset.id, -deduction);
	// }
	// else
	// {
	// lotteryData.freeCount--;
	// }
	// } else {
	// //扣除资源
	// bagInfo.addAsset(lotteryConfig.needAsset.id, -deduction);
	// }
	//
	// bagInfo.addGoods(bisong, true);
	// //抽奖
	// if(buyType == E_LotteryType.ONCE.getCode()){
	//
	// //刷新次数
	// lotteryData.currentNum++;
	// if(lotteryData.currentNum >= 10 ){
	// lotteryData.currentNum -=10;
	// }
	// lotteryData.lastUpdateTime = currentTime;
	// initLotteryResponse(playerController, false);
	// //如果是钻石（高级）抽奖并且抽奖次数是0走初始化配置
	// if(type == E_LotteryType.REPEATEDLY.getCode() && lotteryData.firstLotteryTime
	// == 0){
	// InitDataConfig initDataConfig =
	// DataFactory.getInstance().getInitDataConfig();
	// for (CommonData commonData: initDataConfig.firstLotteryReward){
	// if(commonData.id == playerController.getPlayer().camp){
	// bagInfo.addCard(commonData.value,1);
	// break;
	// }
	// }
	//
	// lotteryData.firstLotteryTime = DataFactory.currentTime;
	//
	// }else{
	// bagInfo.addGoods(lotteryConfig.getDrop());
	// }
	//
	// }else{
	// if(type == E_LotteryType.REPEATEDLY.getCode() ){
	// lotteryData.fistSeniorLotteryTime = DataFactory.currentTime;
	// }
	//
	// LotteryConfig onceLotteryConfig =
	// DataFactory.getInstance().getInitLevelLottery(lotteryConfig.type);
	// //刷新次数
	// lotteryData.currentNum += 10;
	// if(lotteryData.currentNum >= 40){
	// lotteryData.currentNum -=40;
	// }
	// initLotteryResponse(playerController,false);
	//// //循环9次获取奖励
	// for (int i = 0; i < 9; i++) {
	// bagInfo.addGoods(onceLotteryConfig.getDrop());
	// }
	// bagInfo.addGoods(lotteryConfig.getDrop());
	// }
	// b = refreshSeniorLotteryData(b);
	// playerController.sendMsg(SGMainProto.E_MSG_ID.MsgID_Pub_LotteryClick_VALUE,
	// b.build().toByteArray());
	//
	// //抽奖之后检测是否完成任务
	//// taskInfo.checkFinish(ConstantFactory.TASK_TARAGET_LOTTERY, type ==
	// E_LotteryType.REPEATEDLY.getCode() ? 10 :E_LotteryType.ONCE.getCode());
	//
	//
	// FunctionConfig functionConfig =
	// DataFactory.getInstance().getGameObject(DataFactory.FUNCTION_KEY,
	// DataFactory.EVERY_TASK);
	// List<TaskDB> taskDBList = null;
	// if(player.getLv() >= functionConfig.lv){
	// TaskInfo taskInfo = playerController.getPlayer().getExtInfo(TaskInfo.class);
	// //酒馆邂逅
	// if(type == E_LotteryType.ONCE.getCode()){
	// //酒馆邂逅
	// taskDBList =
	// taskInfo.getDoingEveryTask(ConstantFactory.TASK_TARAGET_LOTTERY);
	// for(TaskDB taskDB : taskDBList){
	// if(taskDB.status == SGCommonProto.E_TASK_STATUS.TASK_STATUS_UNDERWAY_VALUE){
	// taskDB.check(ConstantFactory.TASK_TARAGET_LOTTERY, 1);
	// }
	// }
	// }else{
	// taskDBList =
	// taskInfo.getDoingEveryTask(ConstantFactory.TASK_TARAGET_EVERYDAY_LOTTERY);
	// for(TaskDB taskDB : taskDBList){
	// if(taskDB.status == SGCommonProto.E_TASK_STATUS.TASK_STATUS_UNDERWAY_VALUE){
	// taskDB.check(ConstantFactory.TASK_TARAGET_EVERYDAY_LOTTERY, 1);
	// }
	// }
	// }
	//
	// }
	// }

	/**
	 * 抽奖
	 * 
	 * @param playerController
	 * @param type
	 * @param buyType
	 */
	public void getCommonLottery(PlayerController playerController, int type, int buyType) {
		LogUtils.info("抽奖参数->type:", type, ",buyType:", buyType);
		// type = 1 是金币抽 type = 2 是钻石抽 buytype 就是 level 1 是单次抽 2 是多次抽
		if (type != E_LotteryType.ONCE.getCode() && type != E_LotteryType.REPEATEDLY.getCode()) {
			playerController.sendWarn(WordFactory.ILLEGAL_ERROR);
			return;
		}
		if (buyType != E_LotteryType.ONCE.getCode() && buyType != E_LotteryType.REPEATEDLY.getCode()) {
			playerController.sendWarn(WordFactory.ILLEGAL_ERROR);
			return;
		}

		LotteryConfig lotteryConfig = DataFactory.getInstance().getLotteryConfig(type, buyType);
		if (lotteryConfig == null) {
			LogUtils.error("lotteryConfig is null");
			playerController.sendWarn(WordFactory.PARAM_ERROR);
			return;
		}
		// 获取抽奖数据 四种是分别保存的
		LotteryDB lotteryDB = getLotteryDB(lotteryConfig.id);
		if (lotteryDB == null) {
			LogUtils.error("lotteryDB is null");
			playerController.sendWarn(WordFactory.PARAM_ERROR);
			return;
		}
		LogUtils.info("开始抽奖->id:", lotteryConfig.getId(), ",name:", lotteryConfig.getName(), ",lotteryDB freeCount:", lotteryDB.getFreeCount());
		LotteryConfig finalLotteryConfig = null;
		int stableCardId = 0;
		BagInfo bagInfo = playerController.getPlayer().getExtInfo(BagInfo.class);
		LotteryConfig initLotteryConfig = DataFactory.getInstance().getInitLevelLottery(type);

		/**
		 * 三种情况可以进行抽奖 1. 每日免费次数 2. prop中的酒馆酒杯（只有钻石抽奖用 金币的不管他） 3. asset中的资源
		 */
		// 如果是单次抽
		if (buyType == E_LotteryType.ONCE.getCode()) {

			// checkFreeCount的时候如果有免费次数就已经就行了 减减
			if (!lotteryDB.checkFreeCount()) {
				// 拥有的免费道具大于 需要的道具
				int priorityUseCount = bagInfo.getPropCount(lotteryConfig.priorityUse.id);
				if (priorityUseCount >= lotteryConfig.priorityUse.value && priorityUseCount != 0
						&& lotteryConfig.priorityUse.value != 0) {
					// 道具够的情况
					bagInfo.addProp(lotteryConfig.priorityUse.id, -lotteryConfig.priorityUse.value);
				} else {
					// 检测资源是否足够
					if (bagInfo.getAsset(lotteryConfig.needAsset.id) < lotteryConfig.needAsset.value) {
						// 资源不够
						LogUtils.debug("资源不够,需要 -> " + lotteryConfig.needAsset.value + " " + lotteryConfig.getName());
						playerController.sendWarn(WordFactory.ASSET_NOT_ENOUGH, lotteryConfig.needAsset.id);
						return;
					}
					// 资源够用的情况
					bagInfo.addAsset(lotteryConfig.needAsset.id, -lotteryConfig.needAsset.value);

				}
			}

			// 如果是钻石单次抽
			if (lotteryDB instanceof LotteryDiamondSingleDB) {
				if (!((LotteryDiamondSingleDB) lotteryDB).flag) {
					// 钻石单次抽的第一次 每个阵营钻石单次抽的第一次 会获得固定的奖励
					StableDataConfig stableDataConfig = DataFactory.getInstance().getGameObject(
							DataFactory.STABLE_DATA_KEY, E_StableDataType.FIRST_LOTTERY_REWARD.getCode());
					if (stableDataConfig == null) {
						LogUtils.error("StableDataConfig error ->" + "no have type "
								+ E_StableDataType.FIRST_LOTTERY_REWARD.getMsg());
						return;
					}
					stableCardId = stableDataConfig.getFistCardId(playerController.getPlayer().camp);
					finalLotteryConfig = lotteryConfig;
				}
			}
			// 非首次抽奖
			if (stableCardId == 0 && finalLotteryConfig == null) {
				if ((lotteryDB.currentNum + 1) % initLotteryConfig.nextLevelCount == 0) {
					// 抽奖满10次
					finalLotteryConfig = DataFactory.getInstance().getGameObject(DataFactory.LOTTERY_KEY,
							lotteryConfig.nextLevelPond);
				} else {
					// 抽奖不满10次
					finalLotteryConfig = lotteryConfig;
				}
			}
			// 加入 该次 必须得奖励
			bagInfo.addGoods(finalLotteryConfig.reward, true);

			if (stableCardId != 0) {
				// 表示是首次抽奖 所以stableCardId有值 这个奖励根据不同的阵营发放 是固定的
				bagInfo.addCard(stableCardId, 1);
			} else {
				// 不是首次抽奖 根据权重发放奖品
				bagInfo.addGoods(finalLotteryConfig.getDrop());
			}

			// 累计抽奖次数
			lotteryDB.addCurrentCount();
		} else {
			// 十连抽
//			int deduction = 0;
//			if (type == E_LotteryMoneyType.GO.getCode()) {
//				// 金币消耗
//				deduction = 10000 * 10;
//			} else if (type == E_LotteryMoneyType.REPEATEDLY.getCode()) {
//				deduction = 2800;
//			}

			// 因为他这里 使用的是乘 10 的方法 那我们这里也使用乘10 的 方法
			int priorityUseCount = bagInfo.getPropCount(lotteryConfig.priorityUse.id);
			LogUtils.info("配置的优先消耗道具->id:", lotteryConfig.priorityUse.id, ",当前拥有数量->", priorityUseCount,", 配置的数量->", lotteryConfig.priorityUse.value);
			if (priorityUseCount >= lotteryConfig.priorityUse.value && priorityUseCount != 0 && lotteryConfig.priorityUse.value != 0) {
				bagInfo.addProp(lotteryConfig.priorityUse.id, -lotteryConfig.priorityUse.value);
				LogUtils.info("消耗道具--->id:", lotteryConfig.priorityUse.id, ",count->", lotteryConfig.priorityUse.value);
			} else {
				// 检测资源是否足够
				if (bagInfo.getAsset(lotteryConfig.needAsset.id) < lotteryConfig.needAsset.value) {
					// 资源不够
					LogUtils.debug("资源不够,需要 -> " , lotteryConfig.needAsset.value , " " , lotteryConfig.getName());
					playerController.sendWarn(WordFactory.ASSET_NOT_ENOUGH, lotteryConfig.needAsset.id);
					return;
				}

				bagInfo.addAsset(lotteryConfig.needAsset.id, -lotteryConfig.needAsset.value);
				LogUtils.info("消耗道具--->id:", lotteryConfig.needAsset.id, ",count->", lotteryConfig.needAsset.value);
			}

			// 钻石十连抽
			if (lotteryDB instanceof LotteryDiamondMuchDB) {
				// 十连抽固定奖励配置
				StableDataConfig stableDataConfig = DataFactory.getInstance().getGameObject(DataFactory.STABLE_DATA_KEY,
						E_StableDataType.DIAMOND_MUCH_STABLE.getCode());

				// 如果currentNum 不是0 1 返回0 前两次十连抽必得固定的卡牌
				stableCardId = stableDataConfig.getDiamondMuchLotteryCardId(playerController.getPlayer().camp,
						lotteryDB.currentNum);
				if (stableCardId == 0) {
					if ((lotteryDB.currentNum + 1) % lotteryConfig.nextLevelCount == 0) {
						// 高级超级必中
						finalLotteryConfig = DataFactory.getInstance().getGameObject(DataFactory.LOTTERY_KEY,
								lotteryConfig.nextLevelPond);
					} else {
						// 不晋级
						finalLotteryConfig = lotteryConfig;
					}
				}
				// if(!((LotteryDiamondMuchDB) lotteryDB).flag)
				// finalLotteryConfig =
				// DataFactory.getInstance().getGameObject(DataFactory.LOTTERY_KEY,lotteryConfig.nextLevelPond);
				// else
				// {
				// if((lotteryDB.currentNum + 1 )% lotteryConfig.nextLevelCount == 0){
				// finalLotteryConfig =
				// DataFactory.getInstance().getGameObject(DataFactory.LOTTERY_KEY,lotteryConfig.nextLevelPond);
				// }else {
				// finalLotteryConfig = lotteryConfig;
				// }
				// }
			} else if (lotteryDB instanceof LotteryGoldMuchDB) {
				// 金币抽也不会晋级
				finalLotteryConfig = lotteryConfig;
			}

			// 加入必送奖励
			bagInfo.addGoods(lotteryConfig.reward, true);

			for (int i = 0; i < 9; i++) {
				// 循环发放奖励 发放九个奖励 都是普通奖励
				bagInfo.addGoods(initLotteryConfig.getDrop());
			}

			// 补充最后一个奖励 也就是 整卡
			if (stableCardId != 0)
				bagInfo.addCard(stableCardId, 1);
			else
				bagInfo.addGoods(finalLotteryConfig.getDrop());

			lotteryDB.addCurrentCount();
		}

		lotteryDB.setCdTime();

		LogUtils.info("最终真实奖池->", finalLotteryConfig.getId());
		refreshSeniorLotteryData(playerController, finalLotteryConfig.getId());

		// 酒馆邂逅
		if (type == E_LotteryType.ONCE.getCode()) {
			// 酒馆邂逅
			if (buyType == E_LotteryType.REPEATEDLY.getCode()) {
				// 多次抽检测任务是否完成
				playerController.getPlayer().getExtInfo(TaskInfo.class).check(TaskFactory.TASK_TARAGET_LOTTERY, 10);
			} else {
				// 单抽检测任务是否完成
				playerController.getPlayer().getExtInfo(TaskInfo.class).check(TaskFactory.TASK_TARAGET_LOTTERY, 1);
			}
		} else {
			if (buyType == E_LotteryType.REPEATEDLY.getCode()) {
				// 多次抽检测任务是否完成
				playerController.getPlayer().getExtInfo(TaskInfo.class).check(TaskFactory.TASK_TARAGET_EVERYDAY_LOTTERY,
						10);
				//多次抽检测开服活动是否完成
				playerController.getPlayer().getSevenDayData().checkAllRewardState(SevenDayFactory.EVENT_TYPE_4,10);

			} else {
				// 单抽检测任务是否完成
				playerController.getPlayer().getExtInfo(TaskInfo.class).check(TaskFactory.TASK_TARAGET_EVERYDAY_LOTTERY,
						1);
				//单抽抽检测开服活动是否完成
				playerController.getPlayer().getSevenDayData().checkAllRewardState(SevenDayFactory.EVENT_TYPE_4,1);
			}
		}
	}

	/***
	 * 酒馆初始化
	 * 
	 * @param playerController
	 */
	public void initLotteryResponse(PlayerController playerController) {
		hasPushRedPointRemind = false;
		SGPlayerProto.S2C_LotteryInit.Builder response = SGPlayerProto.S2C_LotteryInit.newBuilder();

		LotteryConfig goldSingleLotteryConfig = DataFactory.getInstance().getLotteryConfig(E_LotteryType.ONCE.getCode(),
				E_LotteryType.ONCE.getCode());
		LotteryConfig diamondSingleLotteryConfig = DataFactory.getInstance()
				.getLotteryConfig(E_LotteryType.REPEATEDLY.getCode(), E_LotteryType.ONCE.getCode());
		LotteryConfig diamondMuchLotteryConfig = DataFactory.getInstance()
				.getLotteryConfig(E_LotteryType.REPEATEDLY.getCode(), E_LotteryType.REPEATEDLY.getCode());
		LotteryDB goldSingleLotteryDB = getLotteryDB(goldSingleLotteryConfig.id);
		LotteryDB diamondSingleLotteryDB = getLotteryDB(diamondSingleLotteryConfig.id);
		LotteryDB diamondMuchLotteryDB = getLotteryDB(diamondMuchLotteryConfig.id);

		int leftResidueCount = goldSingleLotteryConfig.nextLevelCount
				- goldSingleLotteryDB.currentNum % goldSingleLotteryConfig.nextLevelCount - 1;
		int rightResidueCount = diamondSingleLotteryConfig.nextLevelCount
				- diamondSingleLotteryDB.currentNum % diamondSingleLotteryConfig.nextLevelCount - 1;
		int rightResidueCount2 = diamondMuchLotteryConfig.nextLevelCount
				- diamondMuchLotteryDB.currentNum % diamondMuchLotteryConfig.nextLevelCount - 1;

		response.setLeftFreeCount(goldSingleLotteryDB.getFreeCount());
		response.setRightFreeCount(diamondSingleLotteryDB.getFreeCount());

		response.setLeftCDTime(goldSingleLotteryDB.getCDTime());
		response.setRightCDTime(diamondSingleLotteryDB.getCDTime());

		response.setLeftResidueCount(leftResidueCount);
		response.setRightResidueCount(rightResidueCount);
		response.setRightResidueCount2(rightResidueCount2);

		LogUtils.debug("response -> " + response);

		playerController.sendMsg(SGMainProto.E_MSG_ID.MsgID_Pub_LotteryInit_VALUE, response.build().toByteArray());

	}

	/***
	 * 酒馆初始化
	 * 
	 * @param playerController
	 */
	// public void initLotteryResponse(PlayerController playerController,boolean bl)
	// {
	// hasPushRedPointRemind = false;
	//
	// SGPlayerProto.S2C_LotteryInit.Builder b =
	// SGPlayerProto.S2C_LotteryInit.newBuilder();
	// SingleBoonData lotteryData = null;
	// LotteryConfig initLotteryConfig = null;
	// //获取次数和剩余CD时间
	// long currentTime = DataFactory.currentTime;
	// lotteryData = lotteryMap.get(1);
	// int leftFreeCount = lotteryData.freeCount;
	// initLotteryConfig =
	// DataFactory.getInstance().getGameObject(DataFactory.LOTTERY_KEY,
	// lotteryData.id);
	// int temp = lotteryData.lastUpdateTime == 0 ? 0 : (int) (currentTime -
	// lotteryData.lastUpdateTime);
	// int leftCDTime;
	// if(lotteryData.lastUpdateTime == 0){
	// leftCDTime = 0;
	// }else{
	// leftCDTime = temp > initLotteryConfig.cdTime ? 0 : initLotteryConfig.cdTime -
	// temp;
	// }
	// int leftResidueCount = initLotteryConfig.nextLevelCount -
	// lotteryData.currentNum % initLotteryConfig.nextLevelCount - 1;
	// lotteryData = lotteryMap.get(2);
	// int rightFreeCount = lotteryData.freeCount;
	// initLotteryConfig =
	// DataFactory.getInstance().getGameObject(DataFactory.LOTTERY_KEY,
	// lotteryData.id);
	// temp = lotteryData.lastUpdateTime == 0 ? 0 : (int) (currentTime -
	// lotteryData.lastUpdateTime);
	// int rightCDTime;
	// if(lotteryData.lastUpdateTime == 0){
	// rightCDTime = 0;
	// }else{
	// rightCDTime = temp > initLotteryConfig.cdTime ? 0 : initLotteryConfig.cdTime
	// - temp;
	// }
	// int rightResidueCount = initLotteryConfig.nextLevelCount -
	// lotteryData.currentNum % initLotteryConfig.nextLevelCount - 1;
	// LotteryConfig highLotteryConfig =
	// DataFactory.getInstance().getNextLevelLottery(initLotteryConfig.type,
	// initLotteryConfig.level);
	// int rightResidueCount2 = highLotteryConfig.nextLevelCount -
	// (lotteryData.currentNum / initLotteryConfig.nextLevelCount) %
	// highLotteryConfig.nextLevelCount - 1;
	//
	// b.setLeftFreeCount(leftFreeCount);
	// b.setLeftCDTime(leftCDTime);
	// b.setLeftResidueCount(leftResidueCount);
	// b.setRightFreeCount(rightFreeCount);
	// b.setRightCDTime(rightCDTime);
	// b.setRightResidueCount(rightResidueCount);
	// b.setRightResidueCount2(rightResidueCount2);
	//
	// if(bl){
	// playerController.sendMsg(SGMainProto.E_MSG_ID.MsgID_Pub_LotteryInit_VALUE,
	// b.build().toByteArray());
	// }
	// }

	// public SGPlayerProto.S2C_LotteryClick.Builder
	// refreshSeniorLotteryData(SGPlayerProto.S2C_LotteryClick.Builder b)
	// {
	// SingleBoonData lotteryData = null;
	// LotteryConfig initLotteryConfig = null;
	// lotteryData = lotteryMap.get(2);
	// initLotteryConfig =
	// DataFactory.getInstance().getGameObject(DataFactory.LOTTERY_KEY,
	// lotteryData.id);
	// int rightResidueCount = initLotteryConfig.nextLevelCount -
	// lotteryData.currentNum % initLotteryConfig.nextLevelCount -1;
	// LotteryConfig highLotteryConfig =
	// DataFactory.getInstance().getNextLevelLottery(initLotteryConfig.type,
	// initLotteryConfig.level);
	// int rightResidueCount2 = highLotteryConfig.nextLevelCount -
	// (lotteryData.currentNum / initLotteryConfig.nextLevelCount) %
	// highLotteryConfig.nextLevelCount -1;
	// b.setRightResidueCount(rightResidueCount);
	// b.setRightResidueCount2(rightResidueCount2);
	// return b;
	// }

	public void refreshSeniorLotteryData(PlayerController playerController, int finalLotteryId)
	{
		LotteryConfig lotteryConfig1 = DataFactory.getInstance().getLotteryConfig(E_LotteryType.REPEATEDLY.getCode(),
				E_LotteryType.ONCE.getCode());
		LotteryConfig lotteryConfig2 = DataFactory.getInstance().getLotteryConfig(E_LotteryType.REPEATEDLY.getCode(),
				E_LotteryType.REPEATEDLY.getCode());
		LotteryDB lotteryDB1 = getLotteryDB(lotteryConfig1.id);
		LotteryDB lotteryDB2 = getLotteryDB(lotteryConfig2.id);

		SGPlayerProto.S2C_LotteryClick.Builder response = SGPlayerProto.S2C_LotteryClick.newBuilder();

		int rightResidueCount = lotteryConfig1.nextLevelCount - lotteryDB1.currentNum % lotteryConfig1.nextLevelCount
				- 1;
		int rightResidueCount2 = lotteryConfig2.nextLevelCount - lotteryDB2.currentNum % lotteryConfig2.nextLevelCount
				- 1;
		response.setRightResidueCount(rightResidueCount);
		response.setRightResidueCount2(rightResidueCount2);
		response.setLotteryType(finalLotteryId);
		playerController.sendMsg(SGMainProto.E_MSG_ID.MsgID_Pub_LotteryClick_VALUE, response.build().toByteArray());
	}

	public LotteryDB getLotteryDB(int id) {
		if (id == goldSingleDB.id)
			return goldSingleDB;

		if (id == goldMuchDB.id)
			return goldMuchDB;

		if (id == diamondSingleDB.id)
			return diamondSingleDB;

		if (id == diamondMuchDB.id)
			return diamondMuchDB;

		LogUtils.error("获取抽奖对象错误, ID -> " + id);
		return null;
	}

	public LotteryDB getDiamondSingleDB() {
		return diamondSingleDB;
	}

	public void setDiamondSingleDB(LotteryDB diamondSingleDB) {
		this.diamondSingleDB = diamondSingleDB;
	}

	public LotteryDB getDiamondMuchDB() {
		return diamondMuchDB;
	}

	public void setDiamondMuchDB(LotteryDB diamondMuchDB) {
		this.diamondMuchDB = diamondMuchDB;
	}
}
